package org.example.finalsecurities.config;

import org.example.finalsecurities.task.*;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Quartz配置类
 * 用于定义和配置定时任务的JobDetail和Trigger
 *
 * @author : [CaiJianbin]
 * @version : [v1.0]
 */
@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail crawlChinaIndexJobDetail() {
        return JobBuilder.newJob(CrawlChinaIndexJob.class)
                .withIdentity("crawlChinaIndexJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger crawlChinaIndexJobTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(crawlChinaIndexJobDetail())
                .withIdentity("crawlChinaIndexTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail crawlNewStockCalendarJobDetail() {
        return JobBuilder.newJob(CrawlNewStockCalendarJob.class)
                .withIdentity("crawlNewStockCalendarJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger crawlNewStockCalendarJobTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(crawlNewStockCalendarJobDetail())
                .withIdentity("crawlNewStockCalendarTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail crawlStockAlertJobDetail() {
        return JobBuilder.newJob(CrawlStockAlertJob.class)
                .withIdentity("crawlStockAlertJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger crawlStockAlertJobTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(crawlStockAlertJobDetail())
                .withIdentity("crawlStockAlertTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail crawlFlowInfoJobDetail() {
        return JobBuilder.newJob(CrawlFlowInfoJob.class)
                .withIdentity("crawlFlowInfoJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger crawlFlowInfoJobTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(crawlFlowInfoJobDetail())
                .withIdentity("crawlFlowInfoTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail crawlChangeInfoJobDetail() {
        return JobBuilder.newJob(CrawlChangeInfoJob.class)
                .withIdentity("crawlChangeInfoJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger crawlChangeInfoJobTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/30 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(crawlChangeInfoJobDetail())
                .withIdentity("crawlChangeInfoTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}
